package com.handpay.zztong.hp.base.model.banklist;

import com.handpay.framework.fastjson.FastJsonHelper;
import com.handpay.zztong.hp.accountcenter.model.SubBankBean;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.base.callback.BusinessEngineListener;
import com.handpay.zztong.hp.base.model.base.BaseModel;
import com.handpay.zztong.hp.config.HttpUrlConstant;

import java.util.Hashtable;

/**
 * Created by lyang on 2017/3/23.
 */

public class BankListModel extends BaseModel {
    private BusinessEngineListener mBusinessEngineListener;


    public boolean doBankProvinceListPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity, HttpUrlConstant.Do_ZztBankProvinceList, params, true, false);
    }

    /**
     * 获取收款行支行列表
     *
     * @param activity
     * @param params
     * @param listener
     * @return
     */


    public boolean doSubBankListPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity, HttpUrlConstant.Do_ZztSubBankList, params, true, false);
    }

    /**
     * 获取收款行主行列表
     *
     * @param activity
     * @param params
     * @param listener
     * @return
     */
    public boolean doBankListPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity, HttpUrlConstant.Do_ZztBankList, params, true, false);
    }

    /**
     * 获取收款行地区列表
     * @param activity
     * @param params
     * @param listener
     * @return
     */
    public boolean doBankAreaListPost(ZZTongActivity activity, Hashtable<String, String> params, BusinessEngineListener listener) {
        mBusinessEngineListener = listener;
        return doPost(activity, HttpUrlConstant.Do_ZztBankAreaList, params, true, false);
    }



    @Override
    public boolean netResponse(String action, byte[] data) {
        boolean bResult = super.netResponse(action, data);
        if (bResult) {
            return true;
        }
        if (action.equals(HttpUrlConstant.Do_ZztBankList)) {
            BankListBean bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, BankListBean.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        } else if (action.equals(HttpUrlConstant.Do_ZztSubBankList)) {
            SubBankBean bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, SubBankBean.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        } else if (action.equals(HttpUrlConstant.Do_ZztBankProvinceList)) {
            BankProvinceListBean bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, BankProvinceListBean.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        }else if (action.equals(HttpUrlConstant.Do_ZztBankAreaList)) {
            BankAreaBean bean = null;
            if (data_type == DATA_TYPE.DATA_TYPE_JSON) {
                try {
                    String result = new String(data, "UTF-8");
                    bean = FastJsonHelper.getObject(result, BankAreaBean.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mBusinessEngineListener != null) {
                mBusinessEngineListener.callbackBusinessResponse(bean);
            }
        }



        return true;
    }
}
